module test_count
    type counter
        real(8)::values
        integer::times
    end type counter
contains
    function cunt(a,n) result(f1)
        real(8)::a(:)
        integer::n
        real(8),allocatable::x(:)
        type(counter),allocatable::f1(:)
        integer::i
        x=a
        i=1
        allocate(f1(n))
        do
            f1(i)%values=x(1)
            f1(i)%times=count(abs(x-x(1))<1.d-7)
            x=pack(x,abs(x-x(1))>1.d-7)
            if(size(x)==0)exit
            i=i+1
        end do
        f1=f1(1:i)
    end function cunt
end module test_count

program main
    use test_count
    implicit none
    real(8)::a(8)
    write(*,*)"test count"
    a=[1,1,1,2,2,3,3,3]
    write(*,*)a
    write(*,*)cunt(a, 8)
end program main
